﻿<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>按钮配置</title>

    <link rel="shortcut icon" href="favicon.ico">
	<link href="css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="css/font-awesome.min.css?v=4.4.0" rel="stylesheet">

    <!-- Data Tables -->
    <link href="css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
    <link href="js/plugins/layui/css/layui.css" rel="stylesheet">
    <link href="css/animate.min.css" rel="stylesheet">
    <link href="css/plugins/jsTree/style.min.css" rel="stylesheet">
    <link href="css/plugins/toastr/toastr.min.css" rel="stylesheet">
    <link href="css/style.min.css?v=4.0.0" rel="stylesheet" />
	<style>
		.mcode{float:right;}
		#layTab_right tr td:nth-child(3){
			text-align:center;
		}
	</style>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight" style="padding-bottom:0px;">
         <div class="row">
            <div class="col-sm-12">
<!-- 页面提示 -->
<div class="collapse" id="collapseExample" style="position:absolute;left:30%;">
	<div class="alert alert-warning alert-dismissable" style="padding:8px;margin-bottom:0px;" >
		<button aria-hidden="true" data-dismiss="alert" style="right:0;" class="close" type="button">×</button>
		该页面只允许超级管理员（开发人员）进行增删改！！！
	</div>
</div>
				<div class="ibox-title"  style="height:72px;">
                        <div class="ibox-tools">
							<a class="collapse-link" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
								<i class="fa fa-warning"></i>
							</a>
                            <a class="collapse-link" href="javascript:location.href=location.href;">
                                <i class="fa fa-refresh"></i>
                            </a>
                        </div>
                        <h5>基本 <small>分类/查找</small></h5>
						<div class="col-sm-12">
							<div class="col-sm-10" style="line-height:34px;color:#DAA520;">
								添加按钮代码时，请采用自定义规则，以便有更强的标识性和可辨别性，如：search、add、update、delete、exp等，
								且系统固有的按钮无法被删除！！！
							</div>
							<div class="col-sm-2 text-right">
								<button id="showAddButton" type="button" class="btn btn-sm btn-success add">新增</button>
							</div>
						</div>
                    </div>
            </div>


        </div>

		<div class="row">
			<div class="col-sm-4">
				<div class="ibox-content" style="padding-left:6px;">

					<div id="jstree1">
						<ul>
						</ul>
					</div>

				</div>
			</div>
			<div class="col-sm-8" style="padding-left:0px;">
				<div class="ibox-content">

					<table id="layTab_right" class="table table-striped table-bordered table-hover dataTables-example">
						<thead>
							<tr>
								<th>按钮名称</th>
								<th width="10%">代码</th>
								<th>状态</th>
								<th>创建人</th>
								<th>创建时间</th>
								<th>更新人</th>
								<th>更新时间</th>
								<th>备注</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
						</tbody>
						<tfoot>

						</tfoot>
					</table>

				</div>
			</div>
		</div>

    </div>


	</div>
    <script src="js/jquery.min.js?v=2.1.4"></script>
    <script src="js/bootstrap.min.js?v=3.3.5"></script>
	<script src="js/plugins/toastr/toastr.min.js"></script>
	<script src="js/plugins/layui/layui.js"></script>
    <script src="js/plugins/jsTree/jstree.min.js"></script>
    <script src="js/plugins/clipboard/clipboard.min.js"></script>
	<script src="js/custom/layTool.js"></script>
    <script type="text/javascript" src="js/custom/app.js" charset="UTF-8"></script>
    <script type="text/javascript" src="js/custom/tools.js" charset="UTF-8"></script>
	<style>
        .jstree-open>.jstree-anchor>.fa-folder:before{content:"\f07c"}.jstree-default .jstree-icon.none{width:0}
    </style>
    <script>
	var menuCode;
	//简单版菜单
	function getSimpleCascadeSysMenuList(){
		var url = 'sysButton/getSimpleCascadeSysMenuList';
		jQuery.ajax({
			url:domain + url,
			type:"get",
			data:{"status":"ON"},
			crossDomain:true,
			xhrFields:{
				withCredentials:true
			},
			success:function (data) {
				if(data.status == 200){
					combMenuHTML(data.data);
				}else{
					top.toastr.warning(data.msg);
				}
			},
			error:function(data) {
				top.toastr.error("查询列表失败，请检查网络");
			}
		})
	}

	function combMenuHTML(data){
		var htmls = new Array();
		for (var i=0;i<data.length;i++){
			var simpleMenu2 = data[i].simpleSysMenuVO;
			var m1Code = data[i].mCode;
			var m1Name = data[i].mName;

			htmls.push('<li class="jstree-open" mcode="'+ m1Code +'">'+ m1Name);
			htmls.push('<ul>');

			for(var j=0;j<simpleMenu2.length;j++){
				var simpleMenu3 = simpleMenu2[j].simpleSysMenuVO;
				var m2Code = simpleMenu2[j].mCode;
				var m2Name = simpleMenu2[j].mName;

				htmls.push('<li class="jstree-open" mcode="'+ m2Code +'">'+ m2Name);
				htmls.push('<ul>');

				for(var k=0;k<simpleMenu3.length;k++){
					var simpleMenu4 = simpleMenu3[k].simpleSysMenuVO;
					var m3Code = simpleMenu3[k].mCode;
					var m3Name = simpleMenu3[k].mName;
					htmls.push('<li class="jstree-open" mcode="'+ m3Code +'">'+ m3Name);
					htmls.push('<ul>');

					for(var l=0;l<simpleMenu4.length;l++){
						var m4Code = simpleMenu4[l].mCode;
						var m4Name = simpleMenu4[l].mName;
						htmls.push('<li class="jstree-open" mcode="'+ m4Code +'">'+ m4Name);
						htmls.push('<span>'+getLock(m4Code)+'&emsp;&emsp;&emsp;&emsp;'+ m4Code +'</span></li>');
					}

					htmls.push('</ul>');
					htmls.push('<span>'+getLock(m3Code)+'&emsp;&emsp;&emsp;&emsp;'+ m3Code +'</span></li>');
				}
				htmls.push('</ul>');
				htmls.push('<span>'+getLock(m2Code)+'&emsp;&emsp;&emsp;&emsp;'+ m2Code +'</span></li>');

			}
			htmls.push('</ul>');
			htmls.push('<span>'+getLock(m1Code)+'&emsp;&emsp;&emsp;&emsp;'+ m1Code +'</span></li>');
		}
		$("#jstree1 ul").html(htmls.join(''));

		$("#jstree1").jstree({
			"core":{"check_callback":true},
			"plugins":["types"],
			"types":{
				"default":{"icon":"fa fa-folder"},
				"html":{"icon":"fa fa-file-code-o"},
				"svg":{"icon":"fa fa-file-picture-o"},
				"css":{"icon":"fa fa-file-code-o"},
				"img":{"icon":"fa fa-file-image-o"},
				"js":{"icon":"fa fa-file-text-o"}
				}
		});

		$('#jstree1').bind("activate_node.jstree", function (obj, e) {
			var currentNode = e.node;
			menuCode = currentNode.li_attr.mcode;
			getSysButtonByMenuCode(menuCode);

			//以下是只能在子菜单中添加按钮
			/*var showButton = currentNode.li_attr.class;
			//console.log(menuCode);
			if(showButton == " showButton"){   //" showButton"
				menuCode = currentNode.li_attr.mcode;
				getSysButtonByMenuCode(menuCode);
			}else{
				menuCode = undefined;
			}*/
		});
	}

	//根据选择菜单获取按钮
	function getSysButtonByMenuCode(menuCode){
		var url = 'sysButton/getSysButtonByMenuCode';
		jQuery.ajax({
			url:domain + url,
			type:"get",
			data:{"menuCode":menuCode},
			crossDomain:true,
			xhrFields:{
				withCredentials:true
			},
			success:function (data) {
				if(data.status == 200){
					combButtonHTML(data.data);
				}else{
					top.toastr.warning(data.msg);
				}
			},
			error:function(data) {
				top.toastr.error("查询列表失败，请检查网络");
			}
		})
	}
	function combButtonHTML(data){
		var htmls = new Array();
		for (var i=0;i<data.length;i++){

			htmls.push('<tr>');
			htmls.push('<td>'+ data[i].bName +'</td>');
			htmls.push('<td>'+ data[i].bCode);
			htmls.push('&nbsp;&nbsp;<button class="btn btn-xs btn-outline btn-info copyBtn'+i+'" onclick="copyText('+i+',\''+ menuCode +'\',\''+data[i].bCode+'\')">复制代码</button></td>');
			htmls.push('<td>'+ getStatus(data[i].status) +'</td>');
			htmls.push('<td>'+ data[i].createBy +'</td>');
			htmls.push('<td>'+ data[i].createTime +'</td>');
			htmls.push('<td>'+ data[i].updateBy +'</td>');
			htmls.push('<td>'+ data[i].updateTime +'</td>');
			htmls.push('<td>'+ data[i].note +'</td>');
			htmls.push('<td><button type="button" data-code="'+ data[i].bCode +'" class="btn btn-xs btn-outline btn-warning showUpdateButton update">修改</button>');
			htmls.push('	<button type="button" data-code="'+ data[i].bCode +'" class="btn btn-xs btn-outline btn-danger showDeleteButton delete">删除</button></td>');

			htmls.push('</tr>');
		}
		$("#layTab_right tbody").html(htmls.join(''));

		//绑定修改按钮事件
		$(".showUpdateButton").on("click",function(){
			var buttonCode = $(this).data("code");
			layerOpen('修改按钮','button-edit.html?buttonCode='+encodeURI(buttonCode)+'&menuCode='+encodeURI(menuCode),'600','330');
		});

		//
		//绑定删除按钮事件
		$(".showDeleteButton").on("click",function(){
			var buttonCode = $(this).data("code");
			deleteSysButton(buttonCode);
		});
	}

	//删除按钮
	function deleteSysButton(buttonCode){
		layui.use(['layer'], function(){
			var layer = layui.layer;
			layer.confirm('确定删除？', {
				title:false,
				icon:7,
				btn: ["确定",'取消'] //按钮
			}, function(){
				var url = 'sysButton/deleteSysButtonByMenuButtonCode';
				jQuery.ajax({
					url:domain + url,
					type:"post",
					data:{"menuCode":menuCode,"buttonCode":buttonCode},
					crossDomain:true,
					xhrFields:{
						withCredentials:true
					},
					success:function (data) {
						if(data.status == 200){
							top.toastr.success("操作成功");
							getSysButtonByMenuCode(menuCode);
							layer.close(layer.index);
						}else{
							top.toastr.warning(data.msg);
						}
					},
					error:function(data) {
						top.toastr.error("查询列表失败，请检查网络");
					}
				})
			});
		});
	}

	$(function(){
		getSimpleCascadeSysMenuList();

		$("#showAddButton").on("click",function(){
			if(menuCode == undefined || menuCode == null || menuCode == ''){
				parent.toastr.error("请先指定一个菜单");
				return;
			}
			layerOpen('新增按钮','button-add.html?menuCode='+encodeURI(menuCode),'600','330');
		})

	})

	var clipboard;
	function copyText(i,menuCode,buttonCode){
		if(clipboard){
			clipboard.destroy();
		}
		var text = '@AuthorizationApi(menu = "'+ menuCode +'",button = "'+ buttonCode +'")';
		clipboard = new Clipboard('.copyBtn'+i,{
			text:function(){
				return text;
			}
		});

		clipboard.on('success', function(e) {
			top.toastr.success("复制成功");
			e.clearSelection();
		});

		clipboard.on('error', function(e) {
			top.toastr.error("复制失败");
		});
	}
	</script>

	<script>	//=======   页面权限显示   ======//
	//当前菜单代码 (每个页面不一样，需要配置)
		var s_menuCode = "btnConf";
	//所有可用权限
		var roleAuth = app.permission(s_menuCode);
	//当前菜单所有可用权限（排除被禁用的按钮）
		var menuAuth = app.menuButtonByOn(s_menuCode);

		drawBtn(roleAuth,menuAuth);
	</script>
</body>

</html>
